package portfolio;

import java.io.Serializable;
import java.util.List;

/**
 * An interface for a Class to interact with the website and database
 * @author Ben Baker
 * @version 1.0
 */
public interface DatabaseParser {
	
	/**
	 * Used to make the innately connection to the database. 
	 * This is usually the first method called.
	 * 
	 * @return TRUE if a connection was made. FALSE if no connection was made
	 */
	public boolean connectToDatabase();
	
	/**
	 * Reads the database. This is intended to populate any local variables.
	 * 
	 * @return TRUE if we are able to read from the Database. Otherwise, FALSE for any errors we encounter
	 * or the database does not exist.
	 * <br><b>Note:</b> It will still return TRUE if the database is empty.
	 */
	public boolean readDatabase();
	
	/**
	 * Adds new {@link Page} to the database. The Page's index must be unique and greater than 0. There cannot 
	 * be duplicate Pages.
	 * 
	 * @param page The page you wish to add to the Database
	 * @see Page
	 * @see Page#equals(Page)
	 * @see Page#compareTo(Page)
	 * @return TRUE if we successfully add a <i>new</i> {@link Page} to the database. FALSE if we encounter
	 * any errors or if a {@link Page} with the same {@link Page#getIndex()} exists.
	 */
	public boolean writeToDatabase(Page page);
	
	/**
	 * Writes to the database all the all the Pages locally saved.
	 * 
	 * @return TRUE if we're successful. FALSE otherwise. 
	 */
	public boolean saveDatabase();
	
	/**
	 * Used to edit a {@link Page} in a database by replacing it with a new one with the same index.
	 * This is a design decision. 
	 * 
	 * @see Page
	 * @see Page#getIndex()	 * 
	 * @param page the new Page you wish to replace the old {@link Page} with 
	 * @param key the index of the old {@link Page} that you wish to replace
	 * @return TRUE if the old {@link Page} is found and replaced. FALSE if the old {@link Page} is not found or 
	 * any other errors are encountered.
	 */
	public boolean replacePageAt(Page page, int key);
	
	/**
	 * If we wish to replace the entire database, we can use this method to replace the database with
	 *  a {@link List}<{@link Page}>.
	 * 
	 * @param pages A {@link List} of {@link Page} that will be stored as the <i>new</i> database. 
	 * Must not be NULL but an empty List is acceptable (but recommended). 
	 * @return TRUE if successful, otherwise FALSE
	 */
	public boolean replaceDatabase(List<Page> pages);
	
	/**
	 * Removes any {@link Page} in the database who's {@link Page#getIndex()} matches the key
	 * 
	 * @see Page
	 * @see Page#getIndex()
	 * @param key the index of the Page you wish to remove
	 * @return TRUE if the {@link Page} is found and removed. FALSE if {@link Page} is not found 
	 *  or any errors are present.
	 */
	public boolean removePageAt(int key);
	
	/**
	 * Closes the connect of the database.
	 * 
	 * @return TRUE if a pre existing connect was close. FALSE if any errors occure.
	 */
	public boolean closeConnection();
	
	/**
	 * Retrieves a List of all Pages in the database.
	 * 
	 * @return a List of all {@link Page} in the database.
	 */
	public List<Page> getAllPages();

	/**
	 * Retrieves a single Page based on the index value
	 * 
	 * @param key the index value you wish to return.
	 * @return the (@link Page} you wish to return. NULL if the Page is not found or errors occure.
	 */
	public Page getPage(int key);
}
